var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
const cors = require('cors')
const adminAuthNext = require('./middlewares/admin-auth')
require('dotenv').config()

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
const adminBook = require('./routes/admin/books')
const adminCategory = require('./routes/admin/categories')
const adminUser = require('./routes/admin/users')
const adminAuth = require('./routes/admin/auth')
const adminLike = require('./routes/admin/likes')
const adminBorrow = require('./routes/admin/borrows')
const auth = require('./routes/auth')

var app = express();

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use(cors())

app.use('/', indexRouter);
app.use('/users', adminAuthNext,usersRouter);
app.use('/admin/books', adminAuthNext,adminBook)
app.use('/admin/categories', adminAuthNext,adminCategory)
app.use('/admin/users', adminUser)
app.use('/admin/likes', adminAuthNext,adminLike)
app.use('/admin/borrows', adminAuthNext,adminBorrow)
app.use('/admin/auth', adminAuth)
app.use('/auth', auth)

module.exports = app;
